package com.draven.copy.code;

import com.draven.copy.code.srv.ProgramService;
import com.draven.copy.code.srv.ProgramServiceImpl;

import java.io.*;
import java.util.Scanner;
public class Main {

    public static void main(String[] args) throws InterruptedException {
        ProgramService programService = new ProgramServiceImpl();
        Scanner scanner = new Scanner(System.in);
        try {
            System.out.println("请输入包含网页源代码的txt文件路径：");
            String fileName = scanner.next();
            System.out.println("读取成功！");

            String webContent = ProgramServiceImpl.readFileContent(fileName);//读取文件目录
            System.out.println("请输入需要保存处理后文件的路径的路径：");
            String outputFileName = scanner.next();
            System.out.println("处理中，请稍后,...");

            Thread.sleep(2000);

            File outputFile = new File(outputFileName);
            if (outputFile.exists()){
                outputFile.delete();
            }
            outputFile.createNewFile();
            FileOutputStream o = new FileOutputStream(outputFileName);
            o.write(programService.process(webContent).getBytes("GBK"));
            o.close(); // 最后记得关闭文件
            System.out.println("处理完成！");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("读取文件内容发生错误!请核对文件路径是否正确");
        }
    }
}
